<div class="layui-card">
    <div class="layui-card-header">
        <h2 class="header-title">订单分佣表</h2>
        <span class="layui-breadcrumb pull-right">
          <a href="#!home">首页</a>
          <a><cite>订单分佣表</cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <div class="layui-form toolbar">
                      搜索：  <select id="ordercommision-search-key">
            <option value="">-请选择-</option>

                <option value="order_no">订单编号 </option>
                 <!--<option value="payee_type">0-平台，1-商家，2-老师，3-会员</option>-->
                 <!--<option value="payee_id">收款人ID,0-平台，business_id-商家，member_id-会员或老师</option>-->
                 <!--<option value="price">佣金金额</option>-->
                 <!--<option value="action">操作类型，0-减少，1-增加</option>-->
                 <!--<option value="create_date">创建时间</option>-->
                 </select>&emsp;
            <input id="ordercommision-search-value" class="layui-input search-input" type="text" placeholder="输入关键字"/>&emsp;
            <button id="ordercommision-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
        </div>

        <table class="layui-table" id="ordercommision-table" lay-filter="ordercommision-table"></table>
    </div>
</div>


<!-- 表格操作列 -->
<script type="text/html" id="ordercommision-table-bar">
 {{#   if(admin.hasPerm("order:ordercommision:update") ){   }}
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
 {{#     } }} 
 <!--{{#  if(admin.hasPerm("order:ordercommision:delete") ){   }}-->
    <!--<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>-->
 <!--{{#     } }} -->
</script>


<!--<script type="text/html" id="toolbar">-->
     <!--{{#  if(admin.hasPerm("order:ordercommision:save")){ }}-->
     <!--<button id="ordercommision-btn-add" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>-->
     <!--{{#     } }} -->
 <!---->
<!--</script>-->

<script type="text/html" id="strPayeeType">
    {{#   if(d.payeeType==0){   }}
    <label class="layui-form-label">平台佣金</label>
    {{#     } }}
    {{#   if(d.payeeType==1){   }}
    <label class="layui-form-label">商家佣金</label>
    {{#     } }}
    {{#   if(d.payeeType==2){   }}
    <label class="layui-form-label">专家分佣</label>
    {{#     } }}
    {{#   if(d.payeeType==3){   }}
    <label class="layui-form-label">会员分佣</label>
    {{#     } }}
</script>

<script type="text/html" id="strAction">
    {{#   if(d.action==0){   }}
    <label class="layui-form-label"  style="color:#cccccc">减少</label>
    {{#     } }}
    {{#   if(d.action==1){   }}
    <label class="layui-form-label" style="color:#FF5722">增加</label>
    {{#     } }}
</script>

<script>
   var admin;
    layui.use(['form', 'table', 'util', 'config', 'admin', 'upload','laytpl','element' ], function () {
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var layer = layui.layer;
        var util = layui.util;
          admin = layui.admin;
        //上传
        var upload = layui.upload;
        let laytpl = layui.laytpl;
        let element = layui.element;

        // 渲染表格
        table.render({
            elem: '#ordercommision-table',
            url: config.base_server + 'order/ordercommision/list',
            method: 'GET',
       
            page: true,
            cols: [[
                {type: 'numbers'},
                            {field: 'payeeType',   title: '分佣归属',toolbar:'#strPayeeType'},
                           // {field: 'id',  title: '佣金账单ID'},
                           {field: 'orderNo',   title: '关联订单'},
                           {field: 'commisionPartName',  title: '收款方'},
                           {field: 'price',   title: '佣金金额'},
                           {field: 'action',   title: '操作类型',toolbar:'#strAction'},
                           {field: 'createDate',  title: '创建时间'},
                        
                {fixed: 'right', align: 'center', toolbar: '#ordercommision-table-bar', title: '操作', width: 175}
            ]]
        });
        
        // laytpl($("#toolbar")[0].innerHTML).render({ }, function(html){
		// 	  $(".layui-card-body .toolbar").append(html);
		// 	  element.render('nav');
		//   });

        // 添加按钮点击事件
        $('#ordercommision-btn-add').click(function () {
            showEditModel();
        });

        // 工具条点击事件
        table.on('tool(ordercommision-table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;

            if (layEvent === 'edit') { // 修改
             
                showEditModel(data);
            }  else if (layEvent === 'del') { // 删除
                layer.confirm('确定删除吗？', function (i) {
                    layer.close(i);
                    layer.load(2);
                    admin.req('order/ordercommision/delete/'+obj.data.id, {}, function (data) {
                        layer.closeAll('loading');
                        if (data.code == 0) {
                            layer.msg(data.msg, {icon: 1, time: 500});
                            table.reload('ordercommision-table', {});
                        } else {
                            layer.msg(data.msg, {icon: 2, time: 500});
                        }
                    }, 'delete');
                });
            }
        });

        //显示表单弹窗
        var showEditModel = function (data) {
        	  var title = data ? '分佣信息' : '添加分佣';
            //修改方法名
            if (data){
                data.method="update"
            }else{
            	data={method:"save"};
            }
 
            admin.putTempData('t_ordercommision', data);
            admin.popupCenter({
                title: title,
                path: 'pages/order/ordercommision_form.html',
                finish: function () {
                    table.reload('ordercommision-table', {});
                }
            });
        };

        // 搜索按钮点击事件
        $('#ordercommision-btn-search').click(function () {
            var key = $('#ordercommision-search-key').val();
            var value = $('#ordercommision-search-value').val();
            table.reload('ordercommision-table', {where: {searchKey: key, searchValue: value}});
        });

    });
</script>
